define(['jquery', 'bootstrap', 'frontend', 'form', 'template'], function ($, undefined, Frontend, Form, Template) {
    // var validatoroptions = {
    //     invalid: function (form, errors) {
    //         $.each(errors, function (i, j) {
    //             Layer.msg(j);
    //         });
    //     }
    // };
    var Controller = {
        index: function () {
            var ws =  new WebSocket("ws://127.0.0.1:8282");
            ws.onopen = function()
            {
                // Web Socket 已连接上，使用 send() 方法发送数据
                // ws.send("发送数据");
                // alert("数据发送中...");
            };
            ws.onmessage = function(e){
                console.log(e.data);
            };
            $(".send-btn").click(function(){

                var teachermessage = '{"type":"teacher","status":"'+1+'","class_id":"'+2+'"}';
                // var studentmessage ='{"data":"'+data_id+'","type":"student"}';
                console.log(teachermessage);
                ws.send(teachermessage);
            });


            $(".close-btn").click(function(){
                var teachermessage = '{"type":"teacher","status":"'+0+'","class_id":"'+2+'"}';
                // var studentmessage ='{"data":"'+data_id+'","type":"student"}';
                console.log(teachermessage);
                ws.send(teachermessage);
            });

            $(".student-btn").click(function(){

                // var text = "2333";
                var data_id =1;
                // var teachermessage = '{"data":"'+"陈云"+'","type":"teacher","status":"'+1+'","class_id":"'+2+'"}';
                var studentmessage ='{"data":"'+data_id+'","type":"student"}';
                console.log(studentmessage);
                // $(".chat-content").append('<div class="chat-text section-right flex"><span class="text"><i class="icon icon-sanjiao3 t-32"></i>'+text+'</span> <span class="char-img" style="background-image: url('+from_head+')"></span> </div>');

                ws.send(studentmessage);

            });

            $(".student2-btn").click(function(){

                // var text = "2333";
                var data_id =2;
                // var teachermessage = '{"data":"'+"陈云"+'","type":"teacher","status":"'+1+'","class_id":"'+2+'"}';
                var studentmessage ='{"data":"'+data_id+'","type":"student"}';
                console.log(studentmessage);
                // $(".chat-content").append('<div class="chat-text section-right flex"><span class="text"><i class="icon icon-sanjiao3 t-32"></i>'+text+'</span> <span class="char-img" style="background-image: url('+from_head+')"></span> </div>');

                ws.send(studentmessage);

            });
        }
    };
    return Controller;
});